package com.zzsy.carosshopprojects.activitys.home.mainpage.oneclickoil;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.activitys.home.mainpage.charge.ChoseOilMode;
import com.zzsy.carosshopprojects.adapter.ChoseOilAdapter;
import com.zzsy.carosshopprojects.base.BaseFragment;
import com.zzsy.carosshopprojects.base.ConfigureFile;
import com.zzsy.carosshopprojects.util.ViewBgUtil;
import com.zzsy.carosshopprojects.view.MyGridView;

import butterknife.BindView;

/**
 * 一键加油
 */
public class OneClickOilFragment extends BaseFragment {
    public static OneClickOilFragment newInstance() {
        OneClickOilFragment oneClickOilFragment = new OneClickOilFragment();
        return oneClickOilFragment;
    }

    private ChoseOilMode choseOilMode;
    @BindView(R.id.recyclerView)
    MyGridView recycleView;
    @BindView(R.id.ly_main)
    LinearLayout ly_main;
    private ChoseOilAdapter choseOilAdapter;

    @Override
    protected int initLayout() {
        return R.layout.fg_oneclickoil;
    }

    @Override
    protected void initView(View view) {
        ly_main.setBackground(ViewBgUtil.setBg(15, Color.parseColor(ConfigureFile.ColorWhite)));
        initTitle(view, getResources().getString(R.string.OneKeyOil), getActivity());
        choseOilAdapter = new ChoseOilAdapter(getContext(), null, 0,false);
        recycleView.setAdapter(choseOilAdapter);
        recycleView.setOnItemClickListener((adapterView, view1, position, l) -> start(QRCodeFragment.newInstance(choseOilAdapter.getListData().get(position).getProductInfoId(),choseOilAdapter.getListData().get(position).getPnumber()+"")));

    }

    @Override
    protected void initData(Context mContext) {
        choseOilMode = getViewModelProvider().get(ChoseOilMode.class);
    }

    @Override
    protected void loadMethod() {
        showListData();
    }

    private void showListData() {
        choseOilMode.getLiveData().observe(this, MenuBeans -> {
            choseOilAdapter.setListData(MenuBeans);
            choseOilAdapter.notifyDataSetChanged();
        });
        choseOilMode.getData(getContext());
    }


}
